<#include "public.ftl">
package ${basePackage}.service.impl;

import com.huitu.annotation.BusinessService;
import com.huitu.whht.hbszy.wrem.common.annotations.SzyWremApiDao;
import com.huitu.whht.hbszy.wrem.common.annotations.SzyWremApiService;
import ${basePackage}.dao.${baseClassName}${props.classNameSuffix}Dao;
import ${basePackage}.entities.${baseClassName};
<#if (pkList?size>1)>import ${basePackage}.entities.${baseClassName}Key;</#if>
import ${basePackage}.entities.${baseClassName}Qo;
import ${basePackage}.service.I${baseClassName}${props.classNameSuffix}Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.springframework.beans.factory.annotation.Autowired;

<#list colList as col><#if (col.columnName == 'TS')>import java.time.LocalDateTime;<#break></#if></#list>
import java.util.List;
import java.util.Map;

/**
 * 说明: ${tab.remarks}Service接口默认实现,表名称: ${tab.tableName} <br/>
 * 日期: ${currentDate}
 * @author ${author}
 */
@Service
@SzyWremApiService
@BusinessService
public class ${baseClassName}${props.classNameSuffix}ServiceImpl implements I${baseClassName}${props.classNameSuffix}Service {

    @Autowired
    @SzyWremApiDao
    private ${baseClassName}${props.classNameSuffix}Dao ${baseInstanceName}${props.classNameSuffix}Dao;

    /**
     * 根据主键查询
     * @param <@serviceMethodPKParamValues pkList=pkList funcs=funcs baseInstanceName=baseInstanceName objectName="pk" hasRemark=true></@serviceMethodPKParamValues>
     * @return 查询结果Map
     */
    @Override
    public Map<String, Object> selectByPrimaryKey(<@serviceMethodPKParams pkList=pkList funcs=funcs baseClassName=baseClassName></@serviceMethodPKParams>) {
        return ${baseInstanceName}${props.classNameSuffix}Dao.selectByPrimaryKey(<@serviceMethodPKParamValues pkList=pkList funcs=funcs baseInstanceName=baseInstanceName objectName="pk"></@serviceMethodPKParamValues>);
    }

    /**
     * 根据条件查询
     * @param filter 查询条件
     * @return 查询结果List
     */
    @Override
    public List<Map<String, Object>> selectList(${baseClassName}Qo filter) {
        return ${baseInstanceName}${props.classNameSuffix}Dao.selectList(filter);
    }

<#if props.partition??>
    /**
     * 根据条件查询最新监测数据
     * @param filter 查询条件
     * @return 最新监测数据List
     */
    @Override
    public List<Map<String, Object>> selectLatest(${baseClassName}Qo filter) {
        return ${baseInstanceName}${props.classNameSuffix}Dao.selectLatest(filter);
    }
</#if>

    /**
     * 新增(null字段会被忽略).
     * 主键值会回填至record对象中
     * @param record 要新增的数据.
     * @return 成功新增的条数.1:新增成功;0:新增失败.
     */
    @Transactional
    @Override
    public Integer insertSelective(${baseClassName} record) {
<#list colList as col>
    <#if col.columnName == 'TS'>
        record.setTs(LocalDateTime.now());
    </#if>
</#list>
        //TODO 在mapper中或service中设置主键,并对record对象中主键字段进行回填
        return ${baseInstanceName}${props.classNameSuffix}Dao.insertSelective(record);
    }

    /**
     * 根据主键按需修改(null字段会被忽略)
     * @param record 要修改的数据
     * @return 成功修改的条数.1:修改成功;0:要修改的数据不存在(可能已被删除)
     */
    @Transactional
    @Override
    public Integer updateByPrimaryKeySelective(${baseClassName} record) {
<#list colList as col>
    <#if col.columnName == 'TS'>
        record.setTs(LocalDateTime.now());
    </#if>
</#list>
        return ${baseInstanceName}${props.classNameSuffix}Dao.updateByPrimaryKeySelective(record);
    }

    /**
     * 根据主键修改
     * @param record 要修改的数据
     * @return 成功修改的条数.1:修改成功;0:要修改的数据不存在(可能已被删除)
     */
    @Transactional
    @Override
    public Integer updateByPrimaryKey(${baseClassName} record) {
<#list colList as col>
    <#if col.columnName == 'TS'>
        record.setTs(LocalDateTime.now());
    </#if>
</#list>
        return ${baseInstanceName}${props.classNameSuffix}Dao.updateByPrimaryKey(record);
    }

    /**
     * 根据主键删除
     * @param <@serviceMethodPKParamValues pkList=pkList funcs=funcs baseInstanceName=baseInstanceName objectName="pk" hasRemark=true></@serviceMethodPKParamValues>
     * @return 成功修改的条数.1:修改成功;0:要删除的数据不存在(可能已被删除)
     */
    @Transactional
    @Override
    public Integer deleteByPrimaryKey(<@serviceMethodPKParams pkList=pkList funcs=funcs baseClassName=baseClassName></@serviceMethodPKParams>) {
        return ${baseInstanceName}${props.classNameSuffix}Dao.deleteByPrimaryKey(<@serviceMethodPKParamValues pkList=pkList funcs=funcs baseInstanceName=baseInstanceName objectName="pk"></@serviceMethodPKParamValues>);
    }

    /**
     * 根据条件删除
     * @param filter 查询条件,符合条件的数据将被删除
     * @return 成功修改的条数.通常1或者>1:删除成功;0:没有符合条件的数据
     */
    @Transactional
    @Override
    public Integer deleteByFilter(${baseClassName}Qo filter){
        return ${baseInstanceName}${props.classNameSuffix}Dao.deleteByFilter(filter);
    }
}
